package com.example.speeddating.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.speeddating.dto.MatchDto;
import com.example.speeddating.entity.Match;
import com.example.speeddating.entity.User;
import com.example.speeddating.mapper.MatchMapper;
import com.example.speeddating.service.MatchService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDate;
import java.time.LocalTime;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author tina
 * @since 2023-07-21 08:00:57
 */
@Service
public class MatchServiceImpl extends ServiceImpl<MatchMapper, Match> implements MatchService {

    @Autowired
    private MatchMapper matchMapper;

    @Override
    public List<Long> selectMatchedUserId(Long userId) {
        return matchMapper.selectMatchedUserId(userId);
    }

    @Override
    public Page<User> selectMatchUser(Integer pageNum,Integer pageSize,Long userId) {
        Page<User> page = new Page<>();
        return matchMapper.selectMatchUser(page,userId);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public void updateMatchByUserId(Long id) {
        matchMapper.updateMatchUser(id);
    }

    @Override
    public Integer getMatchNum(Long userId) {
        return matchMapper.selectCountMatchNum(userId);
    }

    @Override
    public Integer getMatchNum() {
        return matchMapper.selectCountMatchNum();
    }

    @Override
    public Integer getTotalNum() {
        return matchMapper.selectCountTotalMatchNum();
    }

    @Override
    public void insertMatchUser(Long userId, Long matchId) {
        Match match = new Match();
        match.setUserId(userId);
        match.setMatchId(matchId);
        matchMapper.insertMatch(match);
    }

    @Override
    public Integer getLeaveNum(Long id) {
        return matchMapper.selectLeaveCount(id);
    }


    @Override
    public ArrayList<MatchDto> getWeekMatch() {
        return matchMapper.selectWeekMatch();
    }
}
